package com.aspose.cells;

class zbwn {
   static Object a(zbwm var0, zabd var1, Cell var2) {
      if (var1.d() != null && (var1.d().size() == 4 || var1.d().size() == 3)) {
         Object var3 = var0.b((zabd)var1.d().get(0), var2);
         if (var3 == null) {
            var3 = 0.0D;
         } else if (var3 instanceof zst) {
            return var3;
         }

         boolean var4 = true;
         Object var5 = zyn.e(var0.b((zabd)var1.d().get(2), var2), var0.c.getSettings().getDate1904());
         if (var5 instanceof zst) {
            return var5;
         } else if (var5 instanceof Double) {
            int var20 = (int)com.aspose.cells.a.c.zi.b(var5) - 1;
            if (var20 < 0) {
               return zst.i;
            } else {
               boolean var6 = true;
               if (var1.d().size() == 4) {
                  Object var7 = var0.b((zabd)var1.d().get(3), var2);
                  if (var7 == null) {
                     zabd var8 = (zabd)var1.d().get(3);
                     var6 = false;
                  } else {
                     if (var7 instanceof zst) {
                        return var7;
                     }

                     switch(zamo.a(var7.getClass())) {
                     case 3:
                        var6 = (Boolean)var7;
                        break;
                     case 14:
                        if ((Double)var7 == 0.0D) {
                           var6 = false;
                        }
                        break;
                     case 16:
                        double var22 = CellsHelper.getDoubleFromDateTime((DateTime)var7, var0.c.getSettings().getDate1904());
                        if (var22 == 0.0D) {
                           var6 = false;
                        }
                        break;
                     case 18:
                        return zst.i;
                     }
                  }
               }

               zabd var21 = (zabd)var1.d().get(1);
               boolean var23 = false;
               boolean var9 = false;
               boolean var10 = false;
               boolean var11 = false;
               Worksheet var12 = null;
               Object var13 = var0.b((zabd)var1.d().get(1), var2);
               int var15;
               if (var13 instanceof Object[][]) {
                  Object[][] var28 = (Object[][])((Object[][])var13);
                  boolean var29 = false;
                  Object var31 = a(var0, var3, var28, var6);
                  if (var31 instanceof Double) {
                     var15 = (int)com.aspose.cells.a.c.zi.b(var31);
                     return var20 >= var28[var15].length ? zst.g : var28[var15][var20];
                  } else {
                     return var31;
                  }
               } else if (var13 instanceof zft) {
                  zft var14 = (zft)var13;
                  var12 = var0.c.getWorksheets().get(var14.b);
                  int var24 = var14.d.StartRow;
                  int var26 = var14.d.StartColumn;
                  int var25 = var14.d.EndRow;
                  int var27 = var14.d.EndColumn;
                  if (var26 + var20 > var27) {
                     return zst.g;
                  } else {
                     var15 = var0.a(var14.b);
                     if (var15 == -1) {
                        var24 = var25;
                     } else if (var25 > var15) {
                        if (var24 == 0 && var25 == 65535 && var6) {
                           double var16 = Math.pow(2.0D, Math.ceil(com.aspose.cells.b.a.zq.a((double)var15, 2.0D)));
                           var15 = (int)var16 - 1;
                        }

                        var25 = var15;
                        if (var24 > var15) {
                           var25 = var24;
                        }
                     }

                     zem var30 = var0.a(var12.getIndex(), var24, var26, var25, var26, true, true, false);
                     if (var30.f != null && var30.f instanceof Object[][]) {
                        Object[][] var17 = (Object[][])((Object[][])var30.f);
                        Object var18 = a(var0, var3, var17, var6);
                        if (var18 instanceof Double) {
                           Cell var19 = var12.getCells().checkCell((int)com.aspose.cells.a.c.zi.b(var18) + var24, var26 + var20);
                           return var19 == null ? null : var0.a(var19);
                        } else {
                           return var18;
                        }
                     } else {
                        return zst.c;
                     }
                  }
               } else {
                  return zst.g;
               }
            }
         } else {
            return zst.i;
         }
      } else {
         throw new CellsException(5, "Invalid formula in " + var2.d.h().getName() + ":" + var2.i());
      }
   }

   private static Object a(zbwm var0, Object var1, Object[][] var2, boolean var3) {
      if (var1 == null) {
         var1 = 0.0D;
      }

      if (var1 instanceof zst) {
         return var1;
      } else {
         zst var4 = zst.i;
         Object var5;
         switch(zamo.a(var1.getClass())) {
         case 14:
            var5 = a(var0, (Double)var1, var2, var3);
            break;
         case 15:
         case 17:
         default:
            if (var3) {
               var5 = a(var0, com.aspose.cells.b.a.zr.a(var1), 0, var2.length - 1, var2);
            } else {
               var5 = a(var0, com.aspose.cells.b.a.zr.a(var1), var2);
            }
            break;
         case 16:
            var5 = a(var0, CellsHelper.getDoubleFromDateTime((DateTime)var1, var0.c.getSettings().getDate1904()), var2, var3);
            break;
         case 18:
            if (var3) {
               var5 = a(var0, (String)var1, 0, var2.length - 1, var2);
            } else {
               var5 = a(var0, (String)var1, var2);
            }
         }

         return var5;
      }
   }

   private static Object a(zbwm var0, String var1, Object[][] var2) {
      Cell var3 = null;
      String var4 = var1;

      for(int var5 = 0; var5 < var2.length; ++var5) {
         if (var2[var5] != null) {
            Object var6 = var2[var5][0];
            if (var6 != null && var6 instanceof Cell) {
               var3 = (Cell)var6;
               var6 = var0.a(var3);
               var2[var5][0] = var6;
            }

            if (var6 != null) {
               String var7 = com.aspose.cells.b.a.zr.a(var6);
               int var8 = com.aspose.cells.b.a.zv.a(var4, var7, true);
               if (var8 == 0) {
                  return (double)var5;
               }
            }
         }
      }

      return zst.c;
   }

   private static Object a(zbwm var0, String var1, int var2, int var3, Object[][] var4) {
      int var5 = -1;
      Cell var6 = null;
      String var7 = var1.toUpperCase();
      boolean var8 = true;

      while(var2 <= var3) {
         int var12 = (var2 + var3) / 2;
         Object var9 = null;
         if (var4[var12] != null && var4[var12][0] != null) {
            var9 = var4[var12][0];
            if (var9 instanceof Cell) {
               var6 = (Cell)var9;
               var9 = var0.a(var6);
               var4[var12][0] = var9;
            }
         }

         if (var9 == null) {
            Object var14 = a(var0, var1, var12 + 1, var3, var4);
            if (var14 instanceof zst) {
               return a(var0, var1, var2, var12 - 1, var4);
            }

            return var14;
         }

         boolean var10 = false;
         String var11;
         int var13;
         if (var9 instanceof Double) {
            var13 = 1;
         } else {
            var11 = com.aspose.cells.b.a.zr.a(var9).toUpperCase();
            var13 = var7.compareTo(var11);
         }

         if (var13 == 0) {
            for(var5 = var12++; var12 <= var3; ++var12) {
               var9 = null;
               if (var4[var12] != null && var4[var12][0] != null) {
                  var9 = var4[var12][0];
                  if (var9 instanceof Cell) {
                     var6 = (Cell)var9;
                     var9 = var0.a(var6);
                     var4[var12][0] = var9;
                  }
               }

               if (var9 != null) {
                  var11 = com.aspose.cells.b.a.zr.a(var9).toUpperCase();
                  if (!com.aspose.cells.b.a.zv.b(var11, var7)) {
                     return (double)var5;
                  }

                  var5 = var12;
               }
            }

            return (double)var5;
         }

         if (var13 > 0) {
            var5 = var12;
            var2 = var12 + 1;
         } else {
            var3 = var12 - 1;
         }
      }

      if (var5 != -1) {
         return (double)var5;
      } else {
         return zst.c;
      }
   }

   private static Object a(zbwm var0, double var1, int var3, int var4, Object[][] var5) {
      int var6 = -1;
      Cell var7 = null;
      double var8 = 0.0D;
      boolean var10 = true;

      while(var3 <= var4) {
         int var14 = (var3 + var4) / 2;
         Object var11 = null;
         if (var5[var14] != null && var5[var14][0] != null) {
            var11 = var5[var14][0];
            if (var11 instanceof Cell) {
               var7 = (Cell)var11;
               var11 = var0.a(var7);
               var5[var14][0] = var11;
            }
         }

         if (var11 == null || !(var11 instanceof Double)) {
            int var16 = a(var5, var14 + 1, var4);
            Object var13 = null;
            if (var16 != -1) {
               var13 = a(var0, var1, var14 + 1, var16, var5);
               if (!(var13 instanceof zst)) {
                  return var13;
               }
            }

            var16 = a(var5, var3, var14 - 1);
            if (var16 != -1) {
               var13 = a(var0, var1, var3, var16, var5);
               if (!(var13 instanceof zst)) {
                  return var13;
               }
            }

            return var6 != -1 ? (double)var6 : zst.c;
         }

         boolean var12 = false;
         var8 = (Double)var11;
         byte var15;
         if (Math.abs(var1 - var8) < Double.MIN_VALUE) {
            var15 = 0;
         } else if (var1 > var8) {
            var15 = 1;
         } else {
            var15 = -1;
         }

         if (var15 == 0) {
            for(var6 = var14++; var14 <= var4; ++var14) {
               var11 = null;
               if (var5[var14] != null && var5[var14][0] != null) {
                  var11 = var5[var14][0];
                  if (var11 instanceof Cell) {
                     var7 = (Cell)var11;
                     var11 = var0.a(var7);
                     var5[var14][0] = var11;
                  }
               }

               if (var11 != null && var11 instanceof Double) {
                  var8 = (Double)var11;
                  if (Math.abs(var1 - var8) >= Double.MIN_VALUE) {
                     return (double)var6;
                  }

                  var6 = var14;
               }
            }

            return (double)var6;
         }

         if (var15 > 0) {
            var6 = var14;
            var3 = var14 + 1;
         } else {
            var4 = var14 - 1;
         }
      }

      if (var6 != -1) {
         return (double)var6;
      } else {
         return zst.c;
      }
   }

   private static Object a(zbwm var0, double var1, Object[][] var3, boolean var4) {
      if (var4) {
         return a(var0, var1, 0, var3.length - 1, var3);
      } else {
         int var5 = -1;

         for(int var6 = 0; var6 < var3.length; ++var6) {
            if (var3[var6] != null) {
               Object var7 = var3[var6][0];
               if (var7 != null && var7 instanceof Cell) {
                  var7 = var0.a((Cell)var7);
                  var3[var6][0] = var7;
               }

               if (var7 != null && var7 instanceof Double) {
                  double var8 = (Double)var7;
                  if (zbc.a(var1, var8)) {
                     if (!var4) {
                        return (double)var6;
                     }

                     for(var5 = var6++; var6 < var3.length; ++var6) {
                        if (var3[var6] != null) {
                           var7 = var3[var6][0];
                           if (var7 != null && var7 instanceof Cell) {
                              var7 = var0.a((Cell)var7);
                              var3[var6][0] = var7;
                           }

                           if (var7 != null && var7 instanceof Double) {
                              var8 = (Double)var7;
                              if (!zbc.a(var1, var8)) {
                                 return (double)var5;
                              }

                              var5 = var6;
                           }
                        }
                     }
                  } else if (var4 && var1 > var8) {
                     var5 = var6;
                  }
               }
            }
         }

         if (var4) {
            if (var5 != -1) {
               return (double)var5;
            } else {
               return zst.c;
            }
         } else {
            return zst.c;
         }
      }
   }

   static int a(Object[][] var0, int var1, int var2) {
      for(int var3 = var2; var3 >= var1; --var3) {
         if (var0[var3] != null && var0[var3][0] != null) {
            while(var1 <= var2) {
               int var4 = (var1 + var2) / 2;
               if (var4 <= var3) {
                  return var2;
               }

               var2 = var4 - 1;
            }
         }
      }

      return -1;
   }
}
